import {createRouter, createWebHistory, RouteRecordRaw} from 'vue-router';

// 创建路由规则
export const routes: RouteRecordRaw[] = [
    {
        path: '/',
        component: () => import('../views/index.vue'),
        children: [{
            path: 'page1',
            component: () => import('../views/page/page1.vue'),
            meta: {
                title: '页面1'
            }
        }, {
            path: 'page2',
            component: () => import('../views/page/page2.vue'),
            meta: {
                title: '页面2'
            }
        }, {
            path: 'page3',
            component: () => import('../views/page/page3.vue'),
            meta: {
                title: '页面3'
            }
        }, {
            path: '/micro1',
            component: () => import('../views/index.vue'),
            meta: {
                isMicroApp: true,
                microViewPath: '/microApp/micro1'
            }
        }, {
            path: '/micro2',
            component: () => import('../views/index.vue'),
            meta: {
                isMicroApp: true,
                microViewPath: '/microApp/micro2'
            }
        }, {
            path: '/micro3',
            component: () => import('../views/index.vue'),
            meta: {
                isMicroApp: true,
                microViewPath: '/microApp/micro3'
            }
        }]
    },
];
export const getMicroRoutes = (list = routes, routeList: RouteRecordRaw[] = []) => {
    list.forEach(it => {
        const children = it.children ?? []
        it.children && delete it.children
        if (it?.meta?.isMicroApp) {
            routeList.push(it)
        }
        if (children.length) {
            getMicroRoutes(children, routeList)
        }
    })
    return routeList
}
// 创建router实例
const router = createRouter({
    history: createWebHistory(),
    routes,
});

export default router;
